<?php
App::uses('AppController', 'Controller');
/**
 * Clientes Controller
 *
 * @property Cliente $Cliente
 */
class ClientesController extends AppController {

/**
 * admin_index method
 *
 * @return void
 */
	public function admin_index() {
		$this->layout='back_end';
		$this->set('title_for_layout', 'Listado de Propiedades');
		$this->set('listTitle', 'Listado de propiedades');       
		$this->Cliente->recursive = 0;
		$this->set('clientes', $this->paginate());
	}

/**
 * admin_view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function admin_view($id = null) {
		$this->layout='back_end';
		$this->set('title_for_layout', 'Vista de Cliente');
		$this->set('listTitle', 'Vista de Cliente'); 
		$this->Cliente->id = $id;
		if (!$this->Cliente->exists()) {
			throw new NotFoundException(__('Invalid cliente'));
		}
		$this->set('cliente', $this->Cliente->read(null, $id));
	}

/**
 * admin_add method
 *
 * @return void
 */
	public function admin_add() {
		$this->layout='back_end';
		$this->set('title_for_layout', 'Nuevo Cliente');
		$this->set('listTitle', 'Nuevo Cliente'); 
		if ($this->request->is('post')) {
			$this->Cliente->create();
			if ($this->Cliente->save($this->request->data)) {
				$this->flash(__('Cliente saved.'), array('action' => 'index'));
			} else {
			}
		}
		$zonas = $this->Cliente->Zona->find('list');
		$contratos = $this->Cliente->Contrato->find('list');
		$this->set(compact('zonas', 'contratos'));
	}

/**
 * admin_edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function admin_edit($id = null) {
		$this->layout='back_end';
		$this->set('title_for_layout', 'Editar Cliente');
		$this->set('listTitle', 'Editar Cliente'); 
		$this->Cliente->id = $id;
		if (!$this->Cliente->exists()) {
			throw new NotFoundException(__('Invalid cliente'));
		}
		if ($this->request->is('post') || $this->request->is('put')) {
			if ($this->Cliente->save($this->request->data)) {
				$this->flash(__('The cliente has been saved.'), array('action' => 'index'));
				$this->redirect(array('action' => 'index'));
			} else {
			}
		} else {
			$this->request->data = $this->Cliente->read(null, $id);
		}
		$zonas = $this->Cliente->Zona->find('list');
		$contratos = $this->Cliente->Contrato->find('list');
		$this->set(compact('zonas', 'contratos'));
	}

/**
 * admin_delete method
 *
 * @throws MethodNotAllowedException
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function admin_delete($id = null) {
		if (!$this->request->is('post')) {
			throw new MethodNotAllowedException();
		}
		$this->Cliente->id = $id;
		if (!$this->Cliente->exists()) {
			throw new NotFoundException(__('Invalid cliente'));
		}
		if ($this->Cliente->delete()) {
			$this->flash(__('Cliente deleted'), array('action' => 'index'));
		}
		$this->flash(__('Cliente was not deleted'), array('action' => 'index'));
		$this->redirect(array('action' => 'index'));
	}
}
